package com.jixi.controller;

import com.jixi.common.result.PageResult;
import com.jixi.common.result.Result;
import com.jixi.pojo.dto.AccountAddDto;
import com.jixi.pojo.entity.Account;
import com.jixi.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/education")
public class AccountController {
	
	@Autowired
	private AccountService accountService;
	
	/**
	 * 新增账户
	 *
	 * @param accountAddDto 新增账户信息
	 * @return 新增结果
	 */
	@PostMapping("/account/add")
	public Result addAccount(@RequestBody AccountAddDto accountAddDto) {
		return accountService.addAcount(accountAddDto);
	}
	
	/**
	 * 账户列表
	 *
	 * @param pageNum         页码
	 * @param pageSize        每页数量
	 * @param accountType     银行类型
	 * @param accountBankId   账户卡号
	 * @param accountNickname 账户昵称
	 * @param status          状态
	 * @return 账户列表
	 */
	@GetMapping("/account/list")
	public Result<PageResult> accountList(
			Integer pageNum,
			Integer pageSize,
			String accountType,
			String accountBankId,
			String accountNickname,
			Integer status,
			Long educationId
	) {
		return accountService.accountPage(pageNum,pageSize,accountType,accountBankId,accountNickname,status,educationId);
	}
	
	/**
	 * 账户详情
	 *
	 * @param accountId 账户id
	 * @return 账户详情
	 */
	@GetMapping("/account/info")
	public Result<Account> getInfo(Long accountId) {
		Account account = accountService.getAcountInfo(accountId);
		return Result.success(account);
	}
	
	/**
	 * 账户修改
	 *
	 * @param accountId       账户id
	 * @param accountNickname 账户昵称
	 * @param remark          备注
	 * @param status          状态
	 * @param educationId     教育局id
	 * @return 修改结果
	 */
	@PutMapping("/account/update")
	public Result updateAccount(
			Long accountId,
			String accountNickname,
			String remark,
			Integer status,
			Long educationId
	) {
		return accountService.updateAccountById(accountId,accountNickname,remark,status,educationId);
	}
	
	/**
	 * 账户状态修改
	 *
	 * @param accountId 账户id
	 * @param status    状态
	 * @return 修改结果
	 */
	@PutMapping("/account/status")
	public Result updateStatus(Long accountId, Integer status) {
		return accountService.updateAccountStatus(accountId,status);
	}
	
	/**
	 * 账户删除
	 *
	 * @param accountId 账户id
	 * @return 删除结果
	 */
	@DeleteMapping("/account/delete")
	public Result delete(Long accountId) {
		return accountService.deleteAccountById(accountId);
	}
	
}
